package com.caigou.comm.base.repository

import com.caigou.comm.base.bean.HttpResult
import com.caigou.comm.base.network.HttpCommService
import dagger.hilt.android.scopes.ActivityRetainedScoped
import kotlinx.coroutines.flow.Flow
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import javax.inject.Inject

/**
 * @author #Suyghur.
 * Created on 2022/02/24
 */
@ActivityRetainedScoped
class CommRepository @Inject constructor() {

    fun setFollow(followUserId: String, masterUserId: String): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("followUserId", followUserId)
        jsonObject.put("masterUserId", masterUserId)
        val body = jsonObject.toString().toRequestBody()
        return HttpCommService.service.setFollow(body)
    }

    fun buyFlower(userId: String, number: Int): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("userId", userId)
        jsonObject.put("number", number)
        val body = jsonObject.toString().toRequestBody()
        return HttpCommService.service.buyFlower(body)
    }

    fun setReward(type: Int, number: Int, senderId: String, receiverId: String): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("type", type)
        jsonObject.put("number", number)
        jsonObject.put("senderId", senderId)
        jsonObject.put("receiverId", receiverId)
        val body = jsonObject.toString().toRequestBody()
        return HttpCommService.service.setReward(body)
    }

    fun addFriend(senderId: String, receiverId: String, remark: String): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("senderId", senderId)
        jsonObject.put("receiverId", receiverId)
        jsonObject.put("remark", remark)
        val body = jsonObject.toString().toRequestBody()
        return HttpCommService.service.addFriend(body)
    }

    fun delFriend(friendUserId: String, masterUserId: String): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("type", friendUserId)
        jsonObject.put("number", masterUserId)
        val body = jsonObject.toString().toRequestBody()
        return HttpCommService.service.delFriend(body)
    }

    fun setPostReport(submitUserId: String, reportUserId: String, reportCause: String, dataId: Int, type: Int): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("submitUserId", submitUserId)
        jsonObject.put("reportUserId", reportUserId)
        jsonObject.put("reportCause", reportCause)
        jsonObject.put("dataId", dataId)
        jsonObject.put("type", type)
        val body = jsonObject.toString().toRequestBody()
        return HttpCommService.service.setReport(body)
    }

    fun setReplyReport(submitUserId: String, reportUserId: String, reportCause: String, replyId: Int, type: Int): Flow<HttpResult<String>> {
        val jsonObject = JSONObject()
        jsonObject.put("submitUserId", submitUserId)
        jsonObject.put("reportUserId", reportUserId)
        jsonObject.put("reportCause", reportCause)
        jsonObject.put("replyId", replyId)
        jsonObject.put("type", type)
        val body = jsonObject.toString().toRequestBody()
        return HttpCommService.service.setReport(body)
    }
}